// 权限编码集
export const authCodeList = [
  { id: 'table-edit', name: '列表编辑按钮' },
  { id: 'table-add', name: '列表新增按钮' },
  { id: 'table-delete', name: '列表删除按钮' },
  { id: 'table-check', name: '列表审核按钮' },
  { id: 'table-download', name: '列表下载按钮' },
  { id: 'table-upload', name: '列表上传按钮' },
  { id: 'table-detail', name: '列表查看按钮' },
  { id: 'table-member', name: '列表成员按钮' },
  { id: 'table-permission', name: '列表权限按钮' },
  { id: 'table-set', name: '列表设置按钮' },
  { id: 'table-link', name: '列表项按钮' },
  { id: 'delete-all', name: '批量删除按钮' },
  { id: 'set-all', name: '批量设置按钮' },
  { id: 'tab-add', name: '标签新增按钮' },
  { id: 'tab-edit', name: '标签编辑按钮' },
  { id: 'tab-delete', name: '标签删除按钮' },
  { id: 'tab-detail', name: '标签查看按钮' },
  { id: 'tab-set', name: '标签设置按钮' },
  { id: 'tab-save', name: '标签保存按钮' },
  { id: 'tab-cancel', name: '标签取消按钮' },
  { id: 'tab-upload', name: '标签上传按钮' },
  { id: 'tab-download', name: '标签下载按钮' },
  { id: 'tab-import', name: '标签导入按钮' },
  { id: 'tab-export', name: '标签导出按钮' },
  { id: 'tree-add', name: '树节点新增按钮' },
  { id: 'tree-edit', name: '树节点编辑按钮' },
  { id: 'tree-del', name: '树节点删除按钮' },
];

// 混入权限判断
export const mixin = {
  computed: {
    pageAuth() {
      return this.$store.getters.pageAuth || {};
    },
    // 是否管理员
    isAdmin() {
      return this.$store.state.isAdmin;
    },
    // 是否展示列表查看、详情按钮
    hasTableDetail() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-detail' && isCheck === '1';
      });
    },
    // 是否展示列表选项文案操作按钮
    hasTableLink() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-link' && isCheck === '1';
      });
    },
    // 是否展示列表编辑按钮
    hasTableEdit() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-edit' && isCheck === '1';
      });
    },
    // 是否展示列表新增按钮
    hasTableAdd() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-add' && isCheck === '1';
      });
    },
    // 是否展示列表删除按钮
    hasTableDel() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-delete' && isCheck === '1';
      });
    },
    // 是否展示列表审核按钮
    hasTableCheck() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-check' && isCheck === '1';
      });
    },
    // 是否展示列表下载按钮
    hasTableDownLoad() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-download' && isCheck === '1';
      });
    },
    // 是否展示列表上传按钮
    hasTableUpload() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-upload' && isCheck === '1';
      });
    },
    // 是否展示列表设置按钮
    hasTableSet() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-set' && isCheck === '1';
      });
    },
    // 是否展示列表成员按钮
    hasTableMember() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-member' && isCheck === '1';
      });
    },
    // 是否展示列表权限按钮
    hasTablePermission() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'table-permission' && isCheck === '1';
      });
    },
    // 是否展示批量删除按钮
    hasDeleteAll() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'delete-all' && isCheck === '1';
      });
    },
    // 是否展示批量设置按钮
    hasSetAll() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'set-all' && isCheck === '1';
      });
    },
    // 是否展示tab新增按钮
    hasTabAdd() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-add' && isCheck === '1';
      });
    },
    // 是否展示tab编辑按钮
    hasTabEdit() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-edit' && isCheck === '1';
      });
    },
    // 是否展示tab删除按钮
    hasTabDelete() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-delete' && isCheck === '1';
      });
    },
    // 是否展示tab设置按钮
    hasTabSet() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-set' && isCheck === '1';
      });
    },
    // 是否展示取消按钮
    hasCancelBtn() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-cancel' && isCheck === '1';
      });
    },
    // 是否展示保存按钮
    hasSaveBtn() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-save' && isCheck === '1';
      });
    },
    // 是否展示tab上传按钮
    hasTabUpload() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-upload' && isCheck === '1';
      });
    },
    // 是否展示tab下载按钮
    hasTabDownload() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-download' && isCheck === '1';
      });
    },
    // 是否展示tab导入按钮
    hasTabImport() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-import' && isCheck === '1';
      });
    },
    // 是否展示tab导出按钮
    hasTabExport() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-export' && isCheck === '1';
      });
    },
    // 是否展示tab查看按钮
    hasTabDetail() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tab-detail' && isCheck === '1';
      });
    },
    // 是否展示树节点新增按钮
    hasTreeAdd() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tree-add' && isCheck === '1';
      });
    },
    // 是否展示树节点编辑按钮
    hasTreeEdit() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tree-edit' && isCheck === '1';
      });
    },
    // 是否展示树节点删除按钮
    hasTreeDel() {
      const children = this.pageAuth.children || [];
      return this.isAdmin || children.some(item => {
        const { permission, isCheck } = item;
        return permission === 'tree-del' && isCheck === '1';
      });
    },
  }
};
